package admin.common;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import admin.board.board_list.dao.BoardlistDao;
import admin.board.board_list.dto.BoardlistDto;
import admin.board.category.dao.CategoryDao;
import admin.board.category.dto.CategoryDto;
import admin.board.genre.dao.GenreDao;
import admin.board.genre.dto.GenreDto;

public class AdminUtil {
	public static List<Integer> checkPossibleNum(int startNum, int endNum, int parent_no, Object dao) throws SQLException {
		List<Integer> possibleNumList = new ArrayList<Integer>();
		
		/* Category */
		if(dao instanceof CategoryDao) {
			List<CategoryDto> categoryList = ((CategoryDao) dao).list();

			for(int i = startNum; i<=endNum; i++) {
				boolean possible = true;

				for(CategoryDto dto : categoryList) {
					if(i == dto.getCategory_no()) { 
						possible = false;
						break;
					}
				}
				if(possible)
					possibleNumList.add(i);
			}
		}
		
		if(dao instanceof BoardlistDao) {
			List<BoardlistDto> boardList = ((BoardlistDao)dao).list(parent_no);
			
			for(int i = startNum; i <= endNum; i++) {
				boolean possible = true;
				
				for(BoardlistDto dto : boardList) {
					if(i == dto.getBoard_no()) {
						possible = false;
						break;
					}
				}
				if(possible)
					possibleNumList.add(i);
			}
		}
		
		if(dao instanceof GenreDao) {
			List<GenreDto> genreList = ((GenreDao)dao).list(parent_no);
			
			for(int i = startNum; i <= endNum; i++) {
				boolean possible = true;
				
				for(GenreDto dto : genreList) {
					if(i == dto.getGenre_no()) {
						possible = false;
						break;
					}
				}
				if(possible)
					possibleNumList.add(i);
			}
		}
		
		return possibleNumList;
	}
}
